<template>
  <div></div>
</template>

<script>
import { mapActions } from 'vuex'
import { timeFix } from '@/utils/util'
export default {
    data () {
        return {
            paramsInfo: {}
        }
    },
    mounted () {
        this.paramsInfo = JSON.parse(this.getUrlParams(decodeURIComponent(location.href)).userInfo)
        console.log(this.paramsInfo)
        const {
            Login2
        } = this
        Login2(this.paramsInfo)
            .then((res) => {
                console.log(res, 'success')
                this.loginSuccess(res)
            })
            .catch((err) => {
                console.log(err, 'error')
                // this.requestFailed(err)
            })
            .finally(() => {

            })
    },
    methods: {
        ...mapActions(['Login2', 'Logout']),
        getUrlParams (url) {
            // 通过 ? 分割获取后面的参数字符串
            const urlStr = url.split('?')[1]
            // 创建空对象存储参数
            const obj = {}
            // 再通过 & 将每一个参数单独分割出来
            const paramsArr = urlStr.split('&')
            for (let i = 0, len = paramsArr.length; i < len; i++) {
                // 再通过 = 将每一个参数分割为 key:value 的形式
                const arr = paramsArr[i].split('=')
                obj[arr[0]] = arr[1]
            }
            return obj
        },
        loginSuccess (res) {
            console.log(res)
            this.$router.push({ path: '/product/manage/list' })
            // 延迟 1 秒显示欢迎信息
            setTimeout(() => {
                this.$notification.success({
                message: '欢迎',
                description: `${timeFix()}，欢迎回来`
                })
            }, 1000)
            this.isLoginError = false
        },
    }
}
</script>

<style>

</style>